package com.steven.springcloud2orderservicefeign.controller;

import com.steven.springcloud2orderservicefeign.feign.ProductFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author JoeZhou
 */
@RestController
@RequestMapping("/api/v1/order")
public class OrderController {


    private ProductFeign productFeign;

    @Autowired
    public OrderController(ProductFeign productFeign){
        this.productFeign = productFeign;
    }


    @RequestMapping("insert")
    public Map<String, Object> insert(@RequestParam("product-id") int productId) {

        String product = productFeign.selectById(productId);

        Map<String, Object> order = new HashMap<>(3);
        order.put("订单号", UUID.randomUUID().toString());
        order.put("订单时间", new Date());
        order.put("商品", product);

        return order;
    }
}